package com.fuqi.android.zhongcai.utils;

import android.content.Context;
import android.telephony.TelephonyManager;

import com.fuqi.android.zhongcai.application.UniApplication;
import com.fuqi.framework.gson.GsonHelper;

/**
 * Created by junjunli on 15/8/17.
 */
public class DeviceUtils {


    static TelephonyManager tm;

    public static String getDeviceId() {

        if (tm == null) {
            tm = (TelephonyManager) UniApplication.getInstance().getSystemService(Context.TELEPHONY_SERVICE);
        }


        return tm.getDeviceId();

    }


    public static String getDeviceInfo() {

        DeviceInfo deviceInfo = new DeviceInfo();

        if (tm == null) {
            tm = (TelephonyManager) UniApplication.getInstance().getSystemService(Context.TELEPHONY_SERVICE);
        }
        deviceInfo.setDeviceSoftwareVersion(tm.getDeviceSoftwareVersion());
        deviceInfo.setLine1Number(tm.getLine1Number());
        deviceInfo.setNetWorkCountryIso(tm.getNetworkCountryIso());
        deviceInfo.setNetworkOperator(tm.getNetworkOperator());
        deviceInfo.setNetworkOperatorName(tm.getNetworkOperatorName());
        deviceInfo.setNetworkType(tm.getNetworkType());
        deviceInfo.setPhoneType(tm.getPhoneType());
        deviceInfo.setSimCountryIso(tm.getSimCountryIso());
        deviceInfo.setSimOperator(tm.getSimOperator());
        deviceInfo.setSimOperatorName(tm.getSimOperatorName());
        deviceInfo.setSimSerialNumber(tm.getSimSerialNumber());
        deviceInfo.setSimState(tm.getSimState());
        deviceInfo.setSubscriberId(tm.getSubscriberId());
        deviceInfo.setVoiceMailNumber(tm.getVoiceMailNumber());
        return GsonHelper.writeValue(deviceInfo);

    }

}
